home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-07 / netusers.zip / NETUSERS.C < prev    next >
Text File  |  1993-03-18  |  7KB  |  286 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <dos.h>
  4.  
  5. #include "nos.h"
  6. #include "noslib.h"
  7. #include "netusers.h"
  8. #include "version.h"
  9. #include "proto.h"
  10.  
  11. //
  12. //  NETUSERS.EXE
  13. //
  14. //  See Usage () for comments
  15. //
  16. //  This program uses the Borland C versions of the nos library included in
  17. //  the file 'book.zip' on the Artisoft BBS (602-293-0065) and was compiled
  18. //  using Borland C++.
  19. //
  20. //  Written by Alan R. Roney
  21. //
  22. //  Released into the public domain by the author.  The author accepts no
  23. //  responsiblity for any problems associated with use of this program.
  24. //
  25. //  This software is not to be included in any "for profit" software packages.
  26. //
  27. //  You are welcome to modify the source code for this program.  Please
  28. //  forward a copy of your changes to the author.
  29. //
  30. //  Comments and suggested changes should be directed to the author at:
  31. //
  32. //        Compuserve:     76330,3711
  33. //        Internet:        76330.3711@compuserve.com
  34. //        Artisoft:        alan roney
  35. //
  36.  
  37.  
  38. struct serverdef *server;
  39. struct localuserlistdef *localuserlist;
  40. struct localuserlistdef *startup_localuserlist;
  41. struct localuserlistdef *previous_localuserlist;
  42.  
  43. int currentserver, adaptornum, numberoflogins, currentprinter, found;
  44. int userlistjobcount, printjobcount;
  45. int maxlocaluserlistcount, localuserlistcount;
  46. int monoflag, singleflag;
  47.  
  48. char    servername [D_NAMESZ + 2];
  49.  
  50. struct time_block servertime;
  51. struct active_user_entry serveraue;
  52.  
  53. void main (int argc, char *argv [])
  54.     {
  55.     int i, j;
  56.     int show_title;
  57.     char buf [50];
  58.  
  59.     monoflag = false;
  60.     singleflag = false;
  61.     show_title = true;
  62.  
  63.     for (i = 1; i < argc; i++)
  64.     {
  65.     if ( (argv [i] [0] == '-') || (argv [i] [0] == '/') )
  66.         {
  67.         for (j = 1; argv [i] [j] != '\0' ; j++)
  68.         {
  69.         switch (argv [i] [j])
  70.             {
  71.             case 'm':
  72.             case 'M':
  73.             monoflag = true;
  74.             break;
  75.  
  76.             case 's':
  77.             case 'S':
  78.             case '1':
  79.             singleflag = true;
  80.             break;
  81.  
  82.             case 'h':
  83.             case 'H':
  84.             case '?':
  85.             Usage ();
  86.             exit ();
  87.             break;
  88.  
  89.             }
  90.         }
  91.         }
  92.     }
  93.  
  94.     setup ();
  95.  
  96.     do
  97.     {
  98.     getserverinfo ();
  99.  
  100.     if (!singleflag)
  101.         clrscr ();
  102.  
  103.     if (startup_localuserlist [0] .AUE_machine [0] == '\0')
  104.         {
  105.         copy_userlist_to_startup ();
  106.         copy_userlist_to_update ();
  107.         }
  108.  
  109.     reportinfo ();
  110.  
  111.     if (show_title)
  112.         {
  113.         sprintf (buf, "NETUSERS.EXE   Version %d.%02d\0", MAJOR_VERSION, MINOR_VERSION);
  114.         message (buf, false);
  115.         show_title = false;
  116.         }
  117.  
  118.  
  119.     if (!singleflag)
  120.         {
  121.         copy_userlist_to_update ();
  122.  
  123.         i = 0;
  124.         while (i++ < 2)
  125.         {
  126.         sleep (1);
  127.         if (kbhit () != 0)
  128.             break;
  129.         }
  130.         }
  131.     }while ( (kbhit () == 0) && !singleflag);
  132.  
  133.  
  134.     lowvideo ();
  135.     textcolor (LIGHTGRAY);
  136.     if (!singleflag)
  137.     clrscr ();
  138.  
  139.     free (server);
  140.     free (localuserlist);
  141.     }
  142.  
  143.  
  144. void setup ()
  145.     {
  146.     //    Check for presence of NOS Version 4.0 or greater
  147.  
  148.     if (NOSPresence () == -1)
  149.     {
  150.     printf ("NOS not installed\n");
  151.     exit (1);
  152.     }
  153.  
  154.     if (NOSGetVersion () < 1024)
  155.     {
  156.     printf ("Incorrect NOS Version\n");
  157.     exit (1);
  158.     }
  159.  
  160.     //    Find out how many servers this node is logged into
  161.  
  162.     numberoflogins = 0;
  163.     servername [0] = servername [1] = '\\';
  164.  
  165.     while (NOSGetLogin (&numberoflogins, &servername [2], &adaptornum) != -1)
  166.     numberoflogins++;
  167.  
  168.     if (numberoflogins <= 0)
  169.     {
  170.     printf ("Not logged into to any servers\a\n");
  171.     exit (1);
  172.     }
  173.  
  174.     //    open structures for storing information
  175.  
  176.     if ( (server = (struct serverdef *) calloc (numberoflogins,
  177.     sizeof (struct serverdef))) ==    (struct serverdef *) 0)
  178.     {
  179.     printf ("Couldn't allocate space for server information\n");
  180.     exit (1);
  181.     }
  182.  
  183.     maxlocaluserlistcount = 60;
  184.     if ( (localuserlist = (struct localuserlistdef *)
  185.     calloc (maxlocaluserlistcount, sizeof (struct localuserlistdef)))
  186.      ==  (struct localuserlistdef *) 0)
  187.     {
  188.     printf ("Couldn't allocate space for userlist information\n");
  189.     exit (1);
  190.     }
  191.  
  192.     if ( (previous_localuserlist = (struct localuserlistdef *)
  193.     calloc (maxlocaluserlistcount, sizeof (struct localuserlistdef)))
  194.      ==  (struct localuserlistdef *) 0)
  195.     {
  196.     printf ("Couldn't allocate space for previous userlist information\n");
  197.     exit (1);
  198.     }
  199.  
  200.     if ( (startup_localuserlist = (struct localuserlistdef *)
  201.     calloc (maxlocaluserlistcount, sizeof (struct localuserlistdef)))
  202.      ==  (struct localuserlistdef *) 0)
  203.     {
  204.     printf ("Couldn't allocate space for startup userlist information\n");
  205.     exit (1);
  206.     }
  207.  
  208.     //    Get server names and userlist privileges
  209.  
  210.     currentserver = 0;
  211.  
  212.     while (currentserver < numberoflogins)
  213.     {
  214.     if (NOSGetLogin (¤tserver, &servername [2], &adaptornum) == -1)
  215.         NOSperror ("NOSGetLogin");
  216.  
  217.     strcpy (server [currentserver] .servername, servername);
  218.     currentserver++;
  219.     }
  220.  
  221.     qsort ( (void *) server, numberoflogins, sizeof (struct serverdef), comparestring);
  222.     }
  223.  
  224.  
  225. void Usage ()
  226.     {
  227.     int i;
  228.  
  229.     printf ("\nNETUSERS.EXE   Version");
  230.     printf (" %d.%02d", MAJOR_VERSION, MINOR_VERSION);
  231.     i = BETA_VERSION;
  232.     if (i > 0)
  233.     printf (".%02d", BETA_VERSION);
  234.     printf ("\n\n");
  235.  
  236.     printf ("Displays active user names on all logged on servers.  The display\n");
  237.     printf ("    updates every two seconds.  Users who have requested data from\n");
  238.     printf ("    the server since the last update are highlighted\n\n");
  239.     printf ("Users who are logged on through an adaptor other than 0 will have \n");
  240.     printf ("    an asterisk '*' next to their name.\n\n");
  241.     printf ("If you are using a monochrome monitor, you may need to use the /m\n");
  242.     printf ("    switch to inhibit color selections.\n\n");
  243.     }
  244.  
  245.  
  246. void copy_userlist_to_startup ()
  247.     {
  248.     int i, j;
  249.  
  250.     for (i = 0; i < localuserlistcount; i++)
  251.     {
  252.     strcpy (startup_localuserlist [i] .AUE_machine,
  253.         localuserlist [i] .AUE_machine);
  254.  
  255.     strcpy (startup_localuserlist [i] .name_machine,
  256.         localuserlist [i] .name_machine);
  257.  
  258.     for (j = 0; j < 3; j++)
  259.         startup_localuserlist [i] .AUE_requests [j] =
  260.         localuserlist [i] .AUE_requests [j];
  261.  
  262.     startup_localuserlist [i] .server = localuserlist [i] .server;
  263.     }
  264.     }
  265.  
  266.  
  267. void copy_userlist_to_update ()
  268.     {
  269.     int i, j;
  270.  
  271.     for (i = 0; i < localuserlistcount; i++)
  272.     {
  273.     strcpy (previous_localuserlist [i] .AUE_machine,
  274.         localuserlist [i] .AUE_machine);
  275.  
  276.     strcpy (previous_localuserlist [i] .name_machine,
  277.         localuserlist [i] .name_machine);
  278.  
  279.     for (j = 0; j < 3; j++)
  280.         previous_localuserlist [i] .AUE_requests [j] =
  281.         localuserlist [i] .AUE_requests [j];
  282.  
  283.     previous_localuserlist [i] .server = localuserlist [i] .server;
  284.     }
  285.     }
  286.